# -*- coding: utf-8 -*-
# @Time       : 2019/7/14 上午12:51
# @Author     : Simon
# @Email      :
# @File       : __init__.py.py
# @Software   : PyCharm
# @Description:
import logging
import os
import time
import  sys
from logging import config as log_conf
from config import config
__all__=["logger" ]
sys.stderr = sys.stdout

level=config.LEVEL
rq = time.strftime('%Y-%m-%d', time.localtime(time.time()))
log_path = os.getcwd() + '/log/'
if not os.path.exists(log_path): os.mkdir(log_path)
logfile = log_path + rq + '.log'
log_path = os.path.join(log_path, 'chat.log.'+rq)

log_config = {
    'version': 1.0,
    'formatters': {
        'detail': {
            'format': '%(asctime)s - %(name)s - [%(module)s.line:%(lineno)d] - %(levelname)s - %(message)s',
            'datefmt': "%Y-%m-%d %H:%M:%S",

        },
        'simple': {
            'format': '%(name)s - %(levelname)s - [%(funcname).line:%(lineno)d] - %(message)s',

        },
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'level': level,
            'formatter': 'detail',


        },
        'file': {
            'class': 'logging.handlers.RotatingFileHandler',
            'maxBytes': 1024 * 1024 * 5,
            'backupCount': 10,
            'filename': log_path,
            'level': level,
            'formatter': 'detail',
            'encoding': 'utf-8'},
        'timefile':{
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'formatter': 'detail',
            'filename': log_path,
            'when': 'D',
            'interval': 1,
            'encoding': 'utf8',
            'level': level
        },
        'http':{
            'class':'logging.handlers.HTTPHandler',
            'level':'ERROR',
            'formatter':'detail',
            'host':'app.adpublic.cn:8999',
            'url':'/wxbot/process/alarm',
            'method':'POST'
        }
    },
    'loggers': {
        '': {
            'handlers': ['console', 'timefile'],
            'level': level,
            'propagate': False,
        }

    }
}

log_conf.dictConfig(log_config)

logger = logging.getLogger("logger")
